package controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.gson.Gson;

import bean.User;

public class isLoginController extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		User user=new User();
		Gson gson=new Gson();
		response.setContentType("text/json");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		HttpSession session=request.getSession();
		String username=(String)session.getAttribute("username");
		Integer userid=(Integer)session.getAttribute("userid");
		String action=request.getParameter("action");

		if(action.equals("isLogin")){

		if(username==null)
			user.setLoginflag(0);
		else{
			user.setLoginflag(1);
			user.setUsername(username);
			user.setUserid(userid);
		}
		String userJson=gson.toJson(user);
		out.print(userJson);
		}
		out.flush();
		out.close();
	}

}
